package com.p24.XMLParser;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import android.util.Log;

public class CommonXMLParser {
	private Document doc = null;
	private Element root = null;
	
	public CommonXMLParser(String xmlString) throws Exception {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		
	    dbf.setNamespaceAware(true);
	    dbf.setIgnoringElementContentWhitespace(true);
	    
		DocumentBuilder db = dbf.newDocumentBuilder();
		doc = db.parse(new InputSource(new StringReader(xmlString)));
		
		if (doc == null) {
			Log.e("XMLParser", "Cannot parse DOC");
			throw new Exception("Cannot parse DOC");
		}
		
		root = doc.getDocumentElement();
	}
	
	public Document getDoc() {
		return doc;
	}

	public Element getRoot() {
		return root;
	}
}
